package tech.yingchuan.blogs.util;

/**
 * 次类为摆牛id生成器提供补零
 * @author YcDr 丁广义
 * @version 1.0
 * @date 2018/2/7
 */
public class StringUtils {
    private StringUtils() {

    }

    static final int DEFAULT_LENGTH = 10;

    /**
     * 得到length位的序列号,长度不足length位,前面补0
     *
     * @param seq
     * @param length
     * @return
     */
    public static String getSequence(long seq,int length) {
        String str = String.valueOf(seq);
        int len = str.length();
        if (len >= length) {// 取决于业务规模,应该不会到达10
            return str;
        }
        int rest = length - len;
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < rest; i++) {
            sb.append('0');
        }
        sb.append(str);
        return sb.toString();
    }
}
